﻿#include<iostream>
#include<string.h>
using namespace std;
#define int long long
const int N = 500007;

int cnt[N];

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		int max_cnt = 0;
		int min_val = n + 1;
		memset(cnt, 0, sizeof(cnt));
		for (int i = 0; i < n; i++)
		{
			int val;
			cin >> val;
			min_val = min(min_val, val);
			cnt[val]++;
			max_cnt = max(max_cnt, cnt[val]);
		}
		if (cnt[min_val] == max_cnt)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}